define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function() {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'machine/index' + location.search,
                    add_url: 'machine/add',
                    edit_url: 'machine/edit',
                    del_url: 'machine/del',
                    multi_url: 'machine/multi',
                    import_url: 'machine/import',
                    table: 'machine',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        { checkbox: true },
                        { field: 'id', title: __('Id') },
                        { field: 'nick', title: __('Nick'), operate: 'LIKE' },
                        { field: 'number', title: __('Number'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content },
                        { field: 'binds', title: '绑定状态' },
                        { field: 'is_status', title: __('Is_status'), searchList: { "1": __('Is_status 1'), "2": __('Is_status 2'), "3": __('Is_status 3') }, formatter: Table.api.formatter.status },
                        { field: 'create_time', title: __('Create_time'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime },
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [{
                                name: 'bank',
                                title: __('绑定信息'),
                                // text: __('收款信息'),
                                icon: 'fa fa-bitcoin',
                                classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                url: 'Machine/binds'
                            }, {
                                name: 'qrcode',
                                title: __('推广码'),
                                // text: __('接收'),
                                icon: 'fa fa-qrcode',
                                classname: 'btn btn-primary btn-xs btn-detail btn-dialog',
                                url: 'Machine/qr',
                                extend: 'data-area=\'["450px", "450px"]\''
                            }],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function() {
            Controller.api.bindevent();
        },
        edit: function() {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function() {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});